#!/bin/sh
#
# This is the script for generating files for a specific Dalton test job.
#
# For the .check file ksh or bash is preferred, otherwise use sh
# (and hope it is not the old Bourne shell, which will not work)
#
if [ -x /bin/ksh ]; then
   CHECK_SHELL='#!/bin/ksh'
elif [ -x /bin/bash ]; then
   CHECK_SHELL='#!/bin/bash'
else
   CHECK_SHELL='#!/bin/sh'
fi

#######################################################################
#  TEST DESCRIPTION
#######################################################################
cat > ccsdr12_n2.info <<'%EOF%'
   ccsdr12_n2
   -----------
   Molecule:         N2 
   Wave Function:    CCSD(R12)/A1/B / aug-cc-pVDZ + aug-cc-pVDZ
   Test Purpose:     Check CCSD(R12)/A1/B method with auxiliary basis 
%EOF%

#######################################################################
#  MOLECULE INPUT
#######################################################################
cat > ccsdr12_n2.mol <<'%EOF%'
INTGRL
N2                                                                            
aug-cc-pVDZ aug-cc-pVDZ
    2  0 3  X  Y  Z   0.10D-14
 1      7.    1    3    3    2    1
N        0.0000000000000     0.0000000000000     1.0371572000000
H   9    1
     9046.0000000000        0.0007000000
     1357.0000000000        0.0053890000
      309.3000000000        0.0274060000
       87.7300000000        0.1032070000
       28.5600000000        0.2787230000
       10.2100000000        0.4485400000
        3.8380000000        0.2782380000
        0.7466000000        0.0154400000
        0.2248000000       -0.0028640000
H   9    1
     9046.0000000000       -0.0001530000       
     1357.0000000000       -0.0012080000       
      309.3000000000       -0.0059920000       
       87.7300000000       -0.0245440000       
       28.5600000000       -0.0674590000       
       10.2100000000       -0.1580780000       
        3.8380000000       -0.1218310000       
        0.7466000000        0.5490030000       
        0.2248000000        0.5788150000       
F   2    0
        0.2248000000     
        0.0612400000     
H   4    1
       13.5500000000        0.0399190000    
        2.9170000000        0.2171690000    
        0.7973000000        0.5103190000    
        0.2185000000        0.4622140000    
F   2    0
        0.2185000000    
        0.0561100000    
F   2    0
        0.8170000000   
        0.2300000000   
 2      7.    1    3    3    2    1
N        0.0000000000000     0.0000000000000     1.0371572000000
H   9    1
     9046.0000000000        0.0007000000
     1357.0000000000        0.0053890000
      309.3000000000        0.0274060000
       87.7300000000        0.1032070000
       28.5600000000        0.2787230000
       10.2100000000        0.4485400000
        3.8380000000        0.2782380000
        0.7466000000        0.0154400000
        0.2248000000       -0.0028640000
H   9    1
     9046.0000000000       -0.0001530000       
     1357.0000000000       -0.0012080000       
      309.3000000000       -0.0059920000       
       87.7300000000       -0.0245440000       
       28.5600000000       -0.0674590000       
       10.2100000000       -0.1580780000       
        3.8380000000       -0.1218310000       
        0.7466000000        0.5490030000       
        0.2248000000        0.5788150000       
F   2    0
        0.2248000000     
        0.0612400000     
H   4    1
       13.5500000000        0.0399190000    
        2.9170000000        0.2171690000    
        0.7973000000        0.5103190000    
        0.2185000000        0.4622140000    
F   2    0
        0.2185000000    
        0.0561100000    
F   2    0
        0.8170000000   
        0.2300000000   
%EOF%

#######################################################################
#  DALTON INPUT
#######################################################################
cat > ccsdr12_n2.dal <<'%EOF%'

**DALTON INPUT
.RUN WAVE FUNCTION
*MOLBAS
.R12AUX
**INTEGRALS
.R12
**WAVE FUNCTION
.CC
*ORBITAL INPUT
.MOSTART
 H1DIAG
*SCF IN  
.DOUBLY OCCUPIED
  3 1 1 0 2 0 0 0
.THRESH
 1.0D-10
*CC INPUT
.CCSD
.PRINT
 5   
.FROIMP
  1 0 0 0 1 0 0 0
  0 0 0 0 0 0 0 0
.THRENR
 1.0D-12
.MAX IT
 300
*R12 INPUT
.CC2
 1B
**END OF DALTON INPUT
%EOF%

#######################################################################

 

#######################################################################

#######################################################################
#  CHECK SCRIPT
#######################################################################
echo $CHECK_SHELL >ccsdr12_n2.check
cat >>ccsdr12_n2.check <<'%EOF%'
log=$1

if [ `uname` = Linux ]; then
   GREP="egrep -a"
else
   GREP="egrep"
fi

if $GREP -q "not implemented for parallel calculations" $log; then
   echo "TEST ENDED AS EXPECTED"
   exit 0
fi

#            Total SCF   energy:                  -108.9606500014
#            Total MP2-R12/B energy:              -109.3505715885
#            Total CCSD(R12)/B energy:            -109.3413422968



CRIT1=`$GREP "Total MP2-R12/B energy: *  \-109\.3505715885" $log | wc -l`
TEST[1]=`expr	$CRIT1`
CTRL[1]=2
ERROR[1]="MP2-R12/B ENERGY NOT CORRECT"
CRIT2=`$GREP "Total CCSD\(R12\)/B energy: *  \-109\.3413422968" $log | wc -l`
TEST[2]=`expr	$CRIT2`
CTRL[2]=2
ERROR[2]="CCSD(R12)/B ENERGY NOT CORRECT"
#

PASSED=1
for i in 1 2
do 
   if [ ${TEST[i]} -ne ${CTRL[i]} ]; then
     echo "${ERROR[i]} ( test = ${TEST[i]}; control = ${CTRL[i]} ); "
     PASSED=0
   fi
done 

if [ $PASSED -eq 1 ]
then
  echo TEST ENDED PROPERLY
  exit 0
else
  echo THERE IS A PROBLEM 
  exit 1
fi

%EOF%
#######################################################################
